<?php
/**
 * Magento
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Open Software License (OSL 3.0)
 * that is bundled with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://opensource.org/licenses/osl-3.0.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@magento.com so we can send you a copy immediately.
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade Magento to newer
 * versions in the future. If you wish to customize Magento for your
 * needs please refer to http://www.magento.com for more information.
 *
 * @category    Mage
 * @package     Mage_Adminhtml
 * @copyright  Copyright (c) 2006-2015 X.commerce, Inc. (http://www.magento.com)
 * @license    http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 */

/**
 * Coupon codes grid
 *
 * @category    Mage
 * @package     Mage_Adminhtml
 * @author      Magento Core Team <core@magentocommerce.com>
 */
class Silk_Zgb_Block_Adminhtml_Product_Tab_Warehouse_Grid extends Mage_Adminhtml_Block_Widget_Grid
{
    /**
     * Constructor
     */
    public function __construct()
    {
        parent::__construct();
        $this->setId('warehouseGrid');
        $this->setUseAjax(true);
    }

    /**
     * Prepare collection for grid
     *
     * @return Mage_Adminhtml_Block_Widget_Grid
     */
    protected function _prepareCollection()
    {
        $product = Mage::registry('product');
        $storeId = $this->getRequest()->getParam('store');
        if(!$storeId){
            $websiteId = Mage::helper("qslb")->_getwebsiteId();
        }else{
            $websiteId = Mage::getModel('core/store')->load($storeId)->getWebsiteId();
        }

        /**
         * @var Mage_SalesRule_Model_Resource_Coupon_Collection $collection
         */
        $collection = Mage::getResourceModel('zgb/inventory_collection')
            ->addFieldToFilter('product_id', $this->getRequest()->getParam('id'))
            ->addFieldToFilter('website_id', $websiteId)
            ->addFieldToFilter('canceled', array('neq'=>1))
            ->setOrder('id','desc');

        $this->setCollection($collection);

        return parent::_prepareCollection();
    }

    /**
     * Define grid columns
     *
     * @return Mage_Adminhtml_Block_Widget_Grid
     */
    protected function _prepareColumns()
    {
        $this->addColumn('id', array(
            'header' => Mage::helper('zgb')->__('Id'),
            'index'  => 'id',
            'width' => '10'
        ));

        $this->addColumn('id', array(
            'header' => Mage::helper('zgb')->__('Qty'),
            'index'  => 'qty',
            'width' => '10'
        ));

        $this->addColumn('operation', array(
            'header'   => Mage::helper('zgb')->__('操作'),
            'index'    => 'operation',
            'type'     => 'options',
            'options'  => array(
                '1'=>Mage::helper('adminhtml')->__('入库'),
                '2'=>Mage::helper('adminhtml')->__('出库')
            ),
        ));

        $this->addColumn('order_id', array(
            'header' => Mage::helper('zgb')->__('订单号'),
            'index'  => 'order_id',
            'width' => '20'
        ));

        $this->addColumn('comment', array(
            'header' => Mage::helper('zgb')->__('备注'),
            'index'  => 'comment',
        ));

        $this->addColumn('created_at', array(
            'header' => Mage::helper('salesrule')->__('Created On'),
            'index'  => 'created_at',
            'type'   => 'datetime',
            'align'  => 'center',
            'width'  => '160'
        ));

        //$this->addExportType('*/*/exportCouponsCsv', Mage::helper('customer')->__('CSV'));
        //$this->addExportType('*/*/exportCouponsXml', Mage::helper('customer')->__('Excel XML'));
        return parent::_prepareColumns();
    }

    /**
     * Configure grid mass actions
     *
     * @return Mage_Adminhtml_Block_Promo_Quote_Edit_Tab_Coupons_Grid
     */
    protected function _prepareMassaction()
    {
        // $this->setMassactionIdField('coupon_id');
        // $this->getMassactionBlock()->setFormFieldName('ids');
        // $this->getMassactionBlock()->setUseAjax(true);
        // $this->getMassactionBlock()->setHideFormElement(true);

        // $this->getMassactionBlock()->addItem('delete', array(
        //      'label'=> Mage::helper('adminhtml')->__('Delete'),
        //      'url'  => $this->getUrl('*/*/couponsMassDelete', array('_current' => true)),
        //      'confirm' => Mage::helper('salesrule')->__('Are you sure you want to delete the selected coupon(s)?'),
        //      'complete' => 'refreshCouponCodesGrid'
        // ));

        return $this;
    }

    /**
     * Get grid url
     *
     * @return string
     */
    public function getGridUrl()
    {
        return $this->getUrl('admin_zgb/adminhtml_warehouse/inventoryGrid', array('_current'=> true));
    }
}
